
_fssp:     file format elf32-i386


Disassembly of section .text:

00000000 <barrier_init>:
#include "uthread.h"
#include "barrier.h"


void barrier_init(struct barrier *bar, int num)
{
       0:	55                   	push   %ebp
       1:	89 e5                	mov    %esp,%ebp
       3:	83 ec 18             	sub    $0x18,%esp
	bar->n = num;
       6:	8b 45 08             	mov    0x8(%ebp),%eax
       9:	8b 55 0c             	mov    0xc(%ebp),%edx
       c:	89 10                	mov    %edx,(%eax)
	bar->counter = 0;
       e:	8b 45 08             	mov    0x8(%ebp),%eax
      11:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
	bar->arrival = malloc(sizeof(struct binary_semaphore));
      18:	c7 04 24 08 00 00 00 	movl   $0x8,(%esp)
      1f:	e8 65 0b 00 00       	call   b89 <malloc>
      24:	8b 55 08             	mov    0x8(%ebp),%edx
      27:	89 42 08             	mov    %eax,0x8(%edx)
	bar->departure = malloc(sizeof(struct binary_semaphore));
      2a:	c7 04 24 08 00 00 00 	movl   $0x8,(%esp)
      31:	e8 53 0b 00 00       	call   b89 <malloc>
      36:	8b 55 08             	mov    0x8(%ebp),%edx
      39:	89 42 0c             	mov    %eax,0xc(%edx)
	binary_semaphore_init(bar->arrival, 1);
      3c:	8b 45 08             	mov    0x8(%ebp),%eax
      3f:	8b 40 08             	mov    0x8(%eax),%eax
      42:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
      49:	00 
      4a:	89 04 24             	mov    %eax,(%esp)
      4d:	e8 af 11 00 00       	call   1201 <binary_semaphore_init>
	binary_semaphore_init(bar->departure, 0);
      52:	8b 45 08             	mov    0x8(%ebp),%eax
      55:	8b 40 0c             	mov    0xc(%eax),%eax
      58:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
      5f:	00 
      60:	89 04 24             	mov    %eax,(%esp)
      63:	e8 99 11 00 00       	call   1201 <binary_semaphore_init>
}
      68:	c9                   	leave  
      69:	c3                   	ret    

0000006a <barrier_pass>:

void barrier_pass(struct barrier *bar)
{
      6a:	55                   	push   %ebp
      6b:	89 e5                	mov    %esp,%ebp
      6d:	83 ec 18             	sub    $0x18,%esp
	binary_semaphore_down(bar->arrival);
      70:	8b 45 08             	mov    0x8(%ebp),%eax
      73:	8b 40 08             	mov    0x8(%eax),%eax
      76:	89 04 24             	mov    %eax,(%esp)
      79:	e8 b8 11 00 00       	call   1236 <binary_semaphore_down>
	bar->counter++;
      7e:	8b 45 08             	mov    0x8(%ebp),%eax
      81:	8b 40 04             	mov    0x4(%eax),%eax
      84:	8d 50 01             	lea    0x1(%eax),%edx
      87:	8b 45 08             	mov    0x8(%ebp),%eax
      8a:	89 50 04             	mov    %edx,0x4(%eax)
	if (bar->counter < bar->n)
      8d:	8b 45 08             	mov    0x8(%ebp),%eax
      90:	8b 50 04             	mov    0x4(%eax),%edx
      93:	8b 45 08             	mov    0x8(%ebp),%eax
      96:	8b 00                	mov    (%eax),%eax
      98:	39 c2                	cmp    %eax,%edx
      9a:	7d 10                	jge    ac <barrier_pass+0x42>
		binary_semaphore_up(bar->arrival);
      9c:	8b 45 08             	mov    0x8(%ebp),%eax
      9f:	8b 40 08             	mov    0x8(%eax),%eax
      a2:	89 04 24             	mov    %eax,(%esp)
      a5:	e8 e6 11 00 00       	call   1290 <binary_semaphore_up>
      aa:	eb 0e                	jmp    ba <barrier_pass+0x50>
	else
		binary_semaphore_up(bar->departure);
      ac:	8b 45 08             	mov    0x8(%ebp),%eax
      af:	8b 40 0c             	mov    0xc(%eax),%eax
      b2:	89 04 24             	mov    %eax,(%esp)
      b5:	e8 d6 11 00 00       	call   1290 <binary_semaphore_up>
	binary_semaphore_down(bar->departure);
      ba:	8b 45 08             	mov    0x8(%ebp),%eax
      bd:	8b 40 0c             	mov    0xc(%eax),%eax
      c0:	89 04 24             	mov    %eax,(%esp)
      c3:	e8 6e 11 00 00       	call   1236 <binary_semaphore_down>
	bar->counter--;
      c8:	8b 45 08             	mov    0x8(%ebp),%eax
      cb:	8b 40 04             	mov    0x4(%eax),%eax
      ce:	8d 50 ff             	lea    -0x1(%eax),%edx
      d1:	8b 45 08             	mov    0x8(%ebp),%eax
      d4:	89 50 04             	mov    %edx,0x4(%eax)
	if (bar->counter > 0)
      d7:	8b 45 08             	mov    0x8(%ebp),%eax
      da:	8b 40 04             	mov    0x4(%eax),%eax
      dd:	85 c0                	test   %eax,%eax
      df:	7e 10                	jle    f1 <barrier_pass+0x87>
		binary_semaphore_up(bar->departure);
      e1:	8b 45 08             	mov    0x8(%ebp),%eax
      e4:	8b 40 0c             	mov    0xc(%eax),%eax
      e7:	89 04 24             	mov    %eax,(%esp)
      ea:	e8 a1 11 00 00       	call   1290 <binary_semaphore_up>
      ef:	eb 0e                	jmp    ff <barrier_pass+0x95>
	else
		binary_semaphore_up(bar->arrival);
      f1:	8b 45 08             	mov    0x8(%ebp),%eax
      f4:	8b 40 08             	mov    0x8(%eax),%eax
      f7:	89 04 24             	mov    %eax,(%esp)
      fa:	e8 91 11 00 00       	call   1290 <binary_semaphore_up>
}
      ff:	c9                   	leave  
     100:	c3                   	ret    

00000101 <allReady>:
		{0,0,0,0,0}//state M

};

int allReady()
{
     101:	55                   	push   %ebp
     102:	89 e5                	mov    %esp,%ebp
     104:	83 ec 10             	sub    $0x10,%esp
      int i=0;
     107:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
      for(i=0;i<num_soldiers;i++)
     10e:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     115:	eb 1f                	jmp    136 <allReady+0x35>
      {
        if(states[i] != F)
     117:	a1 54 1b 00 00       	mov    0x1b54,%eax
     11c:	8b 55 fc             	mov    -0x4(%ebp),%edx
     11f:	c1 e2 02             	shl    $0x2,%edx
     122:	01 d0                	add    %edx,%eax
     124:	8b 00                	mov    (%eax),%eax
     126:	83 f8 05             	cmp    $0x5,%eax
     129:	74 07                	je     132 <allReady+0x31>
             return 0;
     12b:	b8 00 00 00 00       	mov    $0x0,%eax
     130:	eb 13                	jmp    145 <allReady+0x44>
};

int allReady()
{
      int i=0;
      for(i=0;i<num_soldiers;i++)
     132:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     136:	a1 50 1b 00 00       	mov    0x1b50,%eax
     13b:	39 45 fc             	cmp    %eax,-0x4(%ebp)
     13e:	7c d7                	jl     117 <allReady+0x16>
      {
        if(states[i] != F)
             return 0;
      }
      return 1;
     140:	b8 01 00 00 00       	mov    $0x1,%eax
}
     145:	c9                   	leave  
     146:	c3                   	ret    

00000147 <printStates>:

void printStates()
{
     147:	55                   	push   %ebp
     148:	89 e5                	mov    %esp,%ebp
     14a:	83 ec 28             	sub    $0x28,%esp
  int i;
      for(i=0;i<num_soldiers;i++)
     14d:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     154:	eb 35                	jmp    18b <printStates+0x44>
      {
        printf(1,"%c ",printstates[states[i]]);
     156:	a1 54 1b 00 00       	mov    0x1b54,%eax
     15b:	8b 55 f4             	mov    -0xc(%ebp),%edx
     15e:	c1 e2 02             	shl    $0x2,%edx
     161:	01 d0                	add    %edx,%eax
     163:	8b 00                	mov    (%eax),%eax
     165:	0f b6 80 20 18 00 00 	movzbl 0x1820(%eax),%eax
     16c:	0f be c0             	movsbl %al,%eax
     16f:	89 44 24 08          	mov    %eax,0x8(%esp)
     173:	c7 44 24 04 ea 12 00 	movl   $0x12ea,0x4(%esp)
     17a:	00 
     17b:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     182:	e8 12 07 00 00       	call   899 <printf>
}

void printStates()
{
  int i;
      for(i=0;i<num_soldiers;i++)
     187:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     18b:	a1 50 1b 00 00       	mov    0x1b50,%eax
     190:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     193:	7c c1                	jl     156 <printStates+0xf>
      {
        printf(1,"%c ",printstates[states[i]]);
      }
      printf(1,"\n");
     195:	c7 44 24 04 ee 12 00 	movl   $0x12ee,0x4(%esp)
     19c:	00 
     19d:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     1a4:	e8 f0 06 00 00       	call   899 <printf>
}
     1a9:	c9                   	leave  
     1aa:	c3                   	ret    

000001ab <findNextState>:

soldier_state findNextState(struct soldier* s)
{
     1ab:	55                   	push   %ebp
     1ac:	89 e5                	mov    %esp,%ebp
     1ae:	83 ec 10             	sub    $0x10,%esp

  soldier_state left_state,right_state;

  //read the state of the soldier to your left:
  if(s->id)
     1b1:	8b 45 08             	mov    0x8(%ebp),%eax
     1b4:	8b 00                	mov    (%eax),%eax
     1b6:	85 c0                	test   %eax,%eax
     1b8:	74 1a                	je     1d4 <findNextState+0x29>
           left_state = states[(s->id)-1];
     1ba:	8b 15 54 1b 00 00    	mov    0x1b54,%edx
     1c0:	8b 45 08             	mov    0x8(%ebp),%eax
     1c3:	8b 00                	mov    (%eax),%eax
     1c5:	83 e8 01             	sub    $0x1,%eax
     1c8:	c1 e0 02             	shl    $0x2,%eax
     1cb:	01 d0                	add    %edx,%eax
     1cd:	8b 00                	mov    (%eax),%eax
     1cf:	89 45 fc             	mov    %eax,-0x4(%ebp)
     1d2:	eb 07                	jmp    1db <findNextState+0x30>
  else          // general
           left_state = X;
     1d4:	c7 45 fc 06 00 00 00 	movl   $0x6,-0x4(%ebp)
  //read the state of the soldier to your right:
  if((s->id+1)<num_soldiers)
     1db:	8b 45 08             	mov    0x8(%ebp),%eax
     1de:	8b 00                	mov    (%eax),%eax
     1e0:	8d 50 01             	lea    0x1(%eax),%edx
     1e3:	a1 50 1b 00 00       	mov    0x1b50,%eax
     1e8:	39 c2                	cmp    %eax,%edx
     1ea:	7d 1a                	jge    206 <findNextState+0x5b>
           right_state = states[(s->id)+1];
     1ec:	8b 15 54 1b 00 00    	mov    0x1b54,%edx
     1f2:	8b 45 08             	mov    0x8(%ebp),%eax
     1f5:	8b 00                	mov    (%eax),%eax
     1f7:	83 c0 01             	add    $0x1,%eax
     1fa:	c1 e0 02             	shl    $0x2,%eax
     1fd:	01 d0                	add    %edx,%eax
     1ff:	8b 00                	mov    (%eax),%eax
     201:	89 45 f8             	mov    %eax,-0x8(%ebp)
     204:	eb 07                	jmp    20d <findNextState+0x62>
  else          // rightmost soldier
           right_state = X;
     206:	c7 45 f8 06 00 00 00 	movl   $0x6,-0x8(%ebp)

  if(right_state != X && left_state != X)
     20d:	83 7d f8 06          	cmpl   $0x6,-0x8(%ebp)
     211:	74 36                	je     249 <findNextState+0x9e>
     213:	83 7d fc 06          	cmpl   $0x6,-0x4(%ebp)
     217:	74 30                	je     249 <findNextState+0x9e>
        return transitionFunction[s->state][left_state][right_state];
     219:	8b 45 08             	mov    0x8(%ebp),%eax
     21c:	8b 48 04             	mov    0x4(%eax),%ecx
     21f:	8b 45 fc             	mov    -0x4(%ebp),%eax
     222:	89 c2                	mov    %eax,%edx
     224:	c1 e2 02             	shl    $0x2,%edx
     227:	01 c2                	add    %eax,%edx
     229:	89 c8                	mov    %ecx,%eax
     22b:	c1 e0 02             	shl    $0x2,%eax
     22e:	01 c8                	add    %ecx,%eax
     230:	8d 0c 85 00 00 00 00 	lea    0x0(,%eax,4),%ecx
     237:	01 c8                	add    %ecx,%eax
     239:	01 c2                	add    %eax,%edx
     23b:	8b 45 f8             	mov    -0x8(%ebp),%eax
     23e:	01 d0                	add    %edx,%eax
     240:	8b 04 85 40 18 00 00 	mov    0x1840(,%eax,4),%eax
     247:	eb 47                	jmp    290 <findNextState+0xe5>

  if (left_state==X)
     249:	83 7d fc 06          	cmpl   $0x6,-0x4(%ebp)
     24d:	75 1b                	jne    26a <findNextState+0xbf>
        return generalTransitionFunction[s->state][right_state];
     24f:	8b 45 08             	mov    0x8(%ebp),%eax
     252:	8b 50 04             	mov    0x4(%eax),%edx
     255:	89 d0                	mov    %edx,%eax
     257:	c1 e0 02             	shl    $0x2,%eax
     25a:	01 d0                	add    %edx,%eax
     25c:	8b 55 f8             	mov    -0x8(%ebp),%edx
     25f:	01 d0                	add    %edx,%eax
     261:	8b 04 85 40 1a 00 00 	mov    0x1a40(,%eax,4),%eax
     268:	eb 26                	jmp    290 <findNextState+0xe5>
  if (right_state==X)
     26a:	83 7d f8 06          	cmpl   $0x6,-0x8(%ebp)
     26e:	75 1b                	jne    28b <findNextState+0xe0>
        return rightmostSoldierTransitionFunction[s->state][left_state];
     270:	8b 45 08             	mov    0x8(%ebp),%eax
     273:	8b 50 04             	mov    0x4(%eax),%edx
     276:	89 d0                	mov    %edx,%eax
     278:	c1 e0 02             	shl    $0x2,%eax
     27b:	01 d0                	add    %edx,%eax
     27d:	8b 55 fc             	mov    -0x4(%ebp),%edx
     280:	01 d0                	add    %edx,%eax
     282:	8b 04 85 c0 1a 00 00 	mov    0x1ac0(,%eax,4),%eax
     289:	eb 05                	jmp    290 <findNextState+0xe5>
  return 0;
     28b:	b8 00 00 00 00       	mov    $0x0,%eax
}
     290:	c9                   	leave  
     291:	c3                   	ret    

00000292 <soldierStep>:

void soldierStep(void* soldier)
{
     292:	55                   	push   %ebp
     293:	89 e5                	mov    %esp,%ebp
     295:	83 ec 28             	sub    $0x28,%esp
   struct soldier* s = (struct soldier*)soldier;
     298:	8b 45 08             	mov    0x8(%ebp),%eax
     29b:	89 45 f4             	mov    %eax,-0xc(%ebp)
   while(!allReady())
     29e:	eb 45                	jmp    2e5 <soldierStep+0x53>
  {

	  s->state=findNextState(s);
     2a0:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2a3:	89 04 24             	mov    %eax,(%esp)
     2a6:	e8 00 ff ff ff       	call   1ab <findNextState>
     2ab:	8b 55 f4             	mov    -0xc(%ebp),%edx
     2ae:	89 42 04             	mov    %eax,0x4(%edx)
      barrier_pass(s->bar);
     2b1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2b4:	8b 40 08             	mov    0x8(%eax),%eax
     2b7:	89 04 24             	mov    %eax,(%esp)
     2ba:	e8 ab fd ff ff       	call   6a <barrier_pass>
      states[s->id] = s->state;
     2bf:	8b 15 54 1b 00 00    	mov    0x1b54,%edx
     2c5:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2c8:	8b 00                	mov    (%eax),%eax
     2ca:	c1 e0 02             	shl    $0x2,%eax
     2cd:	01 c2                	add    %eax,%edx
     2cf:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2d2:	8b 40 04             	mov    0x4(%eax),%eax
     2d5:	89 02                	mov    %eax,(%edx)
      barrier_pass(s->bar);
     2d7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2da:	8b 40 08             	mov    0x8(%eax),%eax
     2dd:	89 04 24             	mov    %eax,(%esp)
     2e0:	e8 85 fd ff ff       	call   6a <barrier_pass>
}

void soldierStep(void* soldier)
{
   struct soldier* s = (struct soldier*)soldier;
   while(!allReady())
     2e5:	e8 17 fe ff ff       	call   101 <allReady>
     2ea:	85 c0                	test   %eax,%eax
     2ec:	74 b2                	je     2a0 <soldierStep+0xe>
	  s->state=findNextState(s);
      barrier_pass(s->bar);
      states[s->id] = s->state;
      barrier_pass(s->bar);
  }
}
     2ee:	c9                   	leave  
     2ef:	c3                   	ret    

000002f0 <main>:

int main(int argc, char *argv[])
{
     2f0:	8d 4c 24 04          	lea    0x4(%esp),%ecx
     2f4:	83 e4 f0             	and    $0xfffffff0,%esp
     2f7:	ff 71 fc             	pushl  -0x4(%ecx)
     2fa:	55                   	push   %ebp
     2fb:	89 e5                	mov    %esp,%ebp
     2fd:	53                   	push   %ebx
     2fe:	51                   	push   %ecx
     2ff:	83 ec 30             	sub    $0x30,%esp
     302:	89 c8                	mov    %ecx,%eax
  num_soldiers = atoi(argv[1]);
     304:	8b 40 04             	mov    0x4(%eax),%eax
     307:	83 c0 04             	add    $0x4,%eax
     30a:	8b 00                	mov    (%eax),%eax
     30c:	89 04 24             	mov    %eax,(%esp)
     30f:	e8 59 03 00 00       	call   66d <atoi>
     314:	a3 50 1b 00 00       	mov    %eax,0x1b50
  int i;
  struct barrier* bar;

  struct soldier* soldiers[num_soldiers];
     319:	a1 50 1b 00 00       	mov    0x1b50,%eax
     31e:	8d 50 ff             	lea    -0x1(%eax),%edx
     321:	89 55 f0             	mov    %edx,-0x10(%ebp)
     324:	c1 e0 02             	shl    $0x2,%eax
     327:	8d 50 03             	lea    0x3(%eax),%edx
     32a:	b8 10 00 00 00       	mov    $0x10,%eax
     32f:	83 e8 01             	sub    $0x1,%eax
     332:	01 d0                	add    %edx,%eax
     334:	c7 45 e4 10 00 00 00 	movl   $0x10,-0x1c(%ebp)
     33b:	ba 00 00 00 00       	mov    $0x0,%edx
     340:	f7 75 e4             	divl   -0x1c(%ebp)
     343:	6b c0 10             	imul   $0x10,%eax,%eax
     346:	29 c4                	sub    %eax,%esp
     348:	8d 44 24 08          	lea    0x8(%esp),%eax
     34c:	83 c0 03             	add    $0x3,%eax
     34f:	c1 e8 02             	shr    $0x2,%eax
     352:	c1 e0 02             	shl    $0x2,%eax
     355:	89 45 ec             	mov    %eax,-0x14(%ebp)
  states = malloc(sizeof(soldier_state)*num_soldiers);
     358:	a1 50 1b 00 00       	mov    0x1b50,%eax
     35d:	c1 e0 02             	shl    $0x2,%eax
     360:	89 04 24             	mov    %eax,(%esp)
     363:	e8 21 08 00 00       	call   b89 <malloc>
     368:	a3 54 1b 00 00       	mov    %eax,0x1b54
  for(i=0;i<num_soldiers;i++)
     36d:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     374:	eb 19                	jmp    38f <main+0x9f>
  {
      soldiers[i] = malloc(sizeof(struct soldier));
     376:	c7 04 24 0c 00 00 00 	movl   $0xc,(%esp)
     37d:	e8 07 08 00 00       	call   b89 <malloc>
     382:	8b 55 ec             	mov    -0x14(%ebp),%edx
     385:	8b 4d f4             	mov    -0xc(%ebp),%ecx
     388:	89 04 8a             	mov    %eax,(%edx,%ecx,4)
  int i;
  struct barrier* bar;

  struct soldier* soldiers[num_soldiers];
  states = malloc(sizeof(soldier_state)*num_soldiers);
  for(i=0;i<num_soldiers;i++)
     38b:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     38f:	a1 50 1b 00 00       	mov    0x1b50,%eax
     394:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     397:	7c dd                	jl     376 <main+0x86>
  {
      soldiers[i] = malloc(sizeof(struct soldier));
  }

  //initialize the  general
  soldiers[0]->state = P;
     399:	8b 45 ec             	mov    -0x14(%ebp),%eax
     39c:	8b 00                	mov    (%eax),%eax
     39e:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
  states[0] = P;
     3a5:	a1 54 1b 00 00       	mov    0x1b54,%eax
     3aa:	c7 00 01 00 00 00    	movl   $0x1,(%eax)

  //and the rest of the soldiers
  for(i=1;i<num_soldiers;i++)
     3b0:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     3b7:	eb 27                	jmp    3e0 <main+0xf0>
  {
      soldiers[i]->state = Q;
     3b9:	8b 45 ec             	mov    -0x14(%ebp),%eax
     3bc:	8b 55 f4             	mov    -0xc(%ebp),%edx
     3bf:	8b 04 90             	mov    (%eax,%edx,4),%eax
     3c2:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
      states[i] = Q;
     3c9:	a1 54 1b 00 00       	mov    0x1b54,%eax
     3ce:	8b 55 f4             	mov    -0xc(%ebp),%edx
     3d1:	c1 e2 02             	shl    $0x2,%edx
     3d4:	01 d0                	add    %edx,%eax
     3d6:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
  //initialize the  general
  soldiers[0]->state = P;
  states[0] = P;

  //and the rest of the soldiers
  for(i=1;i<num_soldiers;i++)
     3dc:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     3e0:	a1 50 1b 00 00       	mov    0x1b50,%eax
     3e5:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     3e8:	7c cf                	jl     3b9 <main+0xc9>
      states[i] = Q;
  }



  bar = malloc(sizeof(struct barrier));
     3ea:	c7 04 24 10 00 00 00 	movl   $0x10,(%esp)
     3f1:	e8 93 07 00 00       	call   b89 <malloc>
     3f6:	89 45 e8             	mov    %eax,-0x18(%ebp)
  barrier_init(bar,num_soldiers + 1);
     3f9:	a1 50 1b 00 00       	mov    0x1b50,%eax
     3fe:	83 c0 01             	add    $0x1,%eax
     401:	89 44 24 04          	mov    %eax,0x4(%esp)
     405:	8b 45 e8             	mov    -0x18(%ebp),%eax
     408:	89 04 24             	mov    %eax,(%esp)
     40b:	e8 f0 fb ff ff       	call   0 <barrier_init>

  uthread_init();
     410:	e8 57 08 00 00       	call   c6c <uthread_init>

  for(i=0;i<num_soldiers;i++)
     415:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     41c:	eb 3a                	jmp    458 <main+0x168>
  {
      soldiers[i]->bar = bar;
     41e:	8b 45 ec             	mov    -0x14(%ebp),%eax
     421:	8b 55 f4             	mov    -0xc(%ebp),%edx
     424:	8b 04 90             	mov    (%eax,%edx,4),%eax
     427:	8b 55 e8             	mov    -0x18(%ebp),%edx
     42a:	89 50 08             	mov    %edx,0x8(%eax)
      soldiers[i]->id = uthread_create(soldierStep,soldiers[i]) - 1;
     42d:	8b 45 ec             	mov    -0x14(%ebp),%eax
     430:	8b 55 f4             	mov    -0xc(%ebp),%edx
     433:	8b 1c 90             	mov    (%eax,%edx,4),%ebx
     436:	8b 45 ec             	mov    -0x14(%ebp),%eax
     439:	8b 55 f4             	mov    -0xc(%ebp),%edx
     43c:	8b 04 90             	mov    (%eax,%edx,4),%eax
     43f:	89 44 24 04          	mov    %eax,0x4(%esp)
     443:	c7 04 24 92 02 00 00 	movl   $0x292,(%esp)
     44a:	e8 ac 08 00 00       	call   cfb <uthread_create>
     44f:	83 e8 01             	sub    $0x1,%eax
     452:	89 03                	mov    %eax,(%ebx)
  bar = malloc(sizeof(struct barrier));
  barrier_init(bar,num_soldiers + 1);

  uthread_init();

  for(i=0;i<num_soldiers;i++)
     454:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     458:	a1 50 1b 00 00       	mov    0x1b50,%eax
     45d:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     460:	7c bc                	jl     41e <main+0x12e>
  {
      soldiers[i]->bar = bar;
      soldiers[i]->id = uthread_create(soldierStep,soldiers[i]) - 1;
  }

  while(!allReady())
     462:	eb 1b                	jmp    47f <main+0x18f>
  {
      printStates();
     464:	e8 de fc ff ff       	call   147 <printStates>
      barrier_pass(bar);
     469:	8b 45 e8             	mov    -0x18(%ebp),%eax
     46c:	89 04 24             	mov    %eax,(%esp)
     46f:	e8 f6 fb ff ff       	call   6a <barrier_pass>
      barrier_pass(bar);
     474:	8b 45 e8             	mov    -0x18(%ebp),%eax
     477:	89 04 24             	mov    %eax,(%esp)
     47a:	e8 eb fb ff ff       	call   6a <barrier_pass>
  {
      soldiers[i]->bar = bar;
      soldiers[i]->id = uthread_create(soldierStep,soldiers[i]) - 1;
  }

  while(!allReady())
     47f:	e8 7d fc ff ff       	call   101 <allReady>
     484:	85 c0                	test   %eax,%eax
     486:	74 dc                	je     464 <main+0x174>
  {
      printStates();
      barrier_pass(bar);
      barrier_pass(bar);
  }
  printStates();
     488:	e8 ba fc ff ff       	call   147 <printStates>

  exit();
     48d:	e8 6a 02 00 00       	call   6fc <exit>
     492:	66 90                	xchg   %ax,%ax

00000494 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
     494:	55                   	push   %ebp
     495:	89 e5                	mov    %esp,%ebp
     497:	57                   	push   %edi
     498:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
     499:	8b 4d 08             	mov    0x8(%ebp),%ecx
     49c:	8b 55 10             	mov    0x10(%ebp),%edx
     49f:	8b 45 0c             	mov    0xc(%ebp),%eax
     4a2:	89 cb                	mov    %ecx,%ebx
     4a4:	89 df                	mov    %ebx,%edi
     4a6:	89 d1                	mov    %edx,%ecx
     4a8:	fc                   	cld    
     4a9:	f3 aa                	rep stos %al,%es:(%edi)
     4ab:	89 ca                	mov    %ecx,%edx
     4ad:	89 fb                	mov    %edi,%ebx
     4af:	89 5d 08             	mov    %ebx,0x8(%ebp)
     4b2:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
     4b5:	5b                   	pop    %ebx
     4b6:	5f                   	pop    %edi
     4b7:	5d                   	pop    %ebp
     4b8:	c3                   	ret    

000004b9 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
     4b9:	55                   	push   %ebp
     4ba:	89 e5                	mov    %esp,%ebp
     4bc:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
     4bf:	8b 45 08             	mov    0x8(%ebp),%eax
     4c2:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
     4c5:	90                   	nop
     4c6:	8b 45 0c             	mov    0xc(%ebp),%eax
     4c9:	0f b6 10             	movzbl (%eax),%edx
     4cc:	8b 45 08             	mov    0x8(%ebp),%eax
     4cf:	88 10                	mov    %dl,(%eax)
     4d1:	8b 45 08             	mov    0x8(%ebp),%eax
     4d4:	0f b6 00             	movzbl (%eax),%eax
     4d7:	84 c0                	test   %al,%al
     4d9:	0f 95 c0             	setne  %al
     4dc:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     4e0:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     4e4:	84 c0                	test   %al,%al
     4e6:	75 de                	jne    4c6 <strcpy+0xd>
    ;
  return os;
     4e8:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     4eb:	c9                   	leave  
     4ec:	c3                   	ret    

000004ed <strcmp>:

int
strcmp(const char *p, const char *q)
{
     4ed:	55                   	push   %ebp
     4ee:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
     4f0:	eb 08                	jmp    4fa <strcmp+0xd>
    p++, q++;
     4f2:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     4f6:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
     4fa:	8b 45 08             	mov    0x8(%ebp),%eax
     4fd:	0f b6 00             	movzbl (%eax),%eax
     500:	84 c0                	test   %al,%al
     502:	74 10                	je     514 <strcmp+0x27>
     504:	8b 45 08             	mov    0x8(%ebp),%eax
     507:	0f b6 10             	movzbl (%eax),%edx
     50a:	8b 45 0c             	mov    0xc(%ebp),%eax
     50d:	0f b6 00             	movzbl (%eax),%eax
     510:	38 c2                	cmp    %al,%dl
     512:	74 de                	je     4f2 <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
     514:	8b 45 08             	mov    0x8(%ebp),%eax
     517:	0f b6 00             	movzbl (%eax),%eax
     51a:	0f b6 d0             	movzbl %al,%edx
     51d:	8b 45 0c             	mov    0xc(%ebp),%eax
     520:	0f b6 00             	movzbl (%eax),%eax
     523:	0f b6 c0             	movzbl %al,%eax
     526:	89 d1                	mov    %edx,%ecx
     528:	29 c1                	sub    %eax,%ecx
     52a:	89 c8                	mov    %ecx,%eax
}
     52c:	5d                   	pop    %ebp
     52d:	c3                   	ret    

0000052e <strlen>:

uint
strlen(char *s)
{
     52e:	55                   	push   %ebp
     52f:	89 e5                	mov    %esp,%ebp
     531:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
     534:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     53b:	eb 04                	jmp    541 <strlen+0x13>
     53d:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     541:	8b 55 fc             	mov    -0x4(%ebp),%edx
     544:	8b 45 08             	mov    0x8(%ebp),%eax
     547:	01 d0                	add    %edx,%eax
     549:	0f b6 00             	movzbl (%eax),%eax
     54c:	84 c0                	test   %al,%al
     54e:	75 ed                	jne    53d <strlen+0xf>
    ;
  return n;
     550:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     553:	c9                   	leave  
     554:	c3                   	ret    

00000555 <memset>:

void*
memset(void *dst, int c, uint n)
{
     555:	55                   	push   %ebp
     556:	89 e5                	mov    %esp,%ebp
     558:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
     55b:	8b 45 10             	mov    0x10(%ebp),%eax
     55e:	89 44 24 08          	mov    %eax,0x8(%esp)
     562:	8b 45 0c             	mov    0xc(%ebp),%eax
     565:	89 44 24 04          	mov    %eax,0x4(%esp)
     569:	8b 45 08             	mov    0x8(%ebp),%eax
     56c:	89 04 24             	mov    %eax,(%esp)
     56f:	e8 20 ff ff ff       	call   494 <stosb>
  return dst;
     574:	8b 45 08             	mov    0x8(%ebp),%eax
}
     577:	c9                   	leave  
     578:	c3                   	ret    

00000579 <strchr>:

char*
strchr(const char *s, char c)
{
     579:	55                   	push   %ebp
     57a:	89 e5                	mov    %esp,%ebp
     57c:	83 ec 04             	sub    $0x4,%esp
     57f:	8b 45 0c             	mov    0xc(%ebp),%eax
     582:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
     585:	eb 14                	jmp    59b <strchr+0x22>
    if(*s == c)
     587:	8b 45 08             	mov    0x8(%ebp),%eax
     58a:	0f b6 00             	movzbl (%eax),%eax
     58d:	3a 45 fc             	cmp    -0x4(%ebp),%al
     590:	75 05                	jne    597 <strchr+0x1e>
      return (char*)s;
     592:	8b 45 08             	mov    0x8(%ebp),%eax
     595:	eb 13                	jmp    5aa <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
     597:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     59b:	8b 45 08             	mov    0x8(%ebp),%eax
     59e:	0f b6 00             	movzbl (%eax),%eax
     5a1:	84 c0                	test   %al,%al
     5a3:	75 e2                	jne    587 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
     5a5:	b8 00 00 00 00       	mov    $0x0,%eax
}
     5aa:	c9                   	leave  
     5ab:	c3                   	ret    

000005ac <gets>:

char*
gets(char *buf, int max)
{
     5ac:	55                   	push   %ebp
     5ad:	89 e5                	mov    %esp,%ebp
     5af:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     5b2:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     5b9:	eb 46                	jmp    601 <gets+0x55>
    cc = read(0, &c, 1);
     5bb:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     5c2:	00 
     5c3:	8d 45 ef             	lea    -0x11(%ebp),%eax
     5c6:	89 44 24 04          	mov    %eax,0x4(%esp)
     5ca:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     5d1:	e8 3e 01 00 00       	call   714 <read>
     5d6:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
     5d9:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     5dd:	7e 2f                	jle    60e <gets+0x62>
      break;
    buf[i++] = c;
     5df:	8b 55 f4             	mov    -0xc(%ebp),%edx
     5e2:	8b 45 08             	mov    0x8(%ebp),%eax
     5e5:	01 c2                	add    %eax,%edx
     5e7:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     5eb:	88 02                	mov    %al,(%edx)
     5ed:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
     5f1:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     5f5:	3c 0a                	cmp    $0xa,%al
     5f7:	74 16                	je     60f <gets+0x63>
     5f9:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     5fd:	3c 0d                	cmp    $0xd,%al
     5ff:	74 0e                	je     60f <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     601:	8b 45 f4             	mov    -0xc(%ebp),%eax
     604:	83 c0 01             	add    $0x1,%eax
     607:	3b 45 0c             	cmp    0xc(%ebp),%eax
     60a:	7c af                	jl     5bb <gets+0xf>
     60c:	eb 01                	jmp    60f <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
     60e:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
     60f:	8b 55 f4             	mov    -0xc(%ebp),%edx
     612:	8b 45 08             	mov    0x8(%ebp),%eax
     615:	01 d0                	add    %edx,%eax
     617:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
     61a:	8b 45 08             	mov    0x8(%ebp),%eax
}
     61d:	c9                   	leave  
     61e:	c3                   	ret    

0000061f <stat>:

int
stat(char *n, struct stat *st)
{
     61f:	55                   	push   %ebp
     620:	89 e5                	mov    %esp,%ebp
     622:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
     625:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     62c:	00 
     62d:	8b 45 08             	mov    0x8(%ebp),%eax
     630:	89 04 24             	mov    %eax,(%esp)
     633:	e8 04 01 00 00       	call   73c <open>
     638:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
     63b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     63f:	79 07                	jns    648 <stat+0x29>
    return -1;
     641:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
     646:	eb 23                	jmp    66b <stat+0x4c>
  r = fstat(fd, st);
     648:	8b 45 0c             	mov    0xc(%ebp),%eax
     64b:	89 44 24 04          	mov    %eax,0x4(%esp)
     64f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     652:	89 04 24             	mov    %eax,(%esp)
     655:	e8 fa 00 00 00       	call   754 <fstat>
     65a:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
     65d:	8b 45 f4             	mov    -0xc(%ebp),%eax
     660:	89 04 24             	mov    %eax,(%esp)
     663:	e8 bc 00 00 00       	call   724 <close>
  return r;
     668:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
     66b:	c9                   	leave  
     66c:	c3                   	ret    

0000066d <atoi>:

int
atoi(const char *s)
{
     66d:	55                   	push   %ebp
     66e:	89 e5                	mov    %esp,%ebp
     670:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
     673:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
     67a:	eb 23                	jmp    69f <atoi+0x32>
    n = n*10 + *s++ - '0';
     67c:	8b 55 fc             	mov    -0x4(%ebp),%edx
     67f:	89 d0                	mov    %edx,%eax
     681:	c1 e0 02             	shl    $0x2,%eax
     684:	01 d0                	add    %edx,%eax
     686:	01 c0                	add    %eax,%eax
     688:	89 c2                	mov    %eax,%edx
     68a:	8b 45 08             	mov    0x8(%ebp),%eax
     68d:	0f b6 00             	movzbl (%eax),%eax
     690:	0f be c0             	movsbl %al,%eax
     693:	01 d0                	add    %edx,%eax
     695:	83 e8 30             	sub    $0x30,%eax
     698:	89 45 fc             	mov    %eax,-0x4(%ebp)
     69b:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
     69f:	8b 45 08             	mov    0x8(%ebp),%eax
     6a2:	0f b6 00             	movzbl (%eax),%eax
     6a5:	3c 2f                	cmp    $0x2f,%al
     6a7:	7e 0a                	jle    6b3 <atoi+0x46>
     6a9:	8b 45 08             	mov    0x8(%ebp),%eax
     6ac:	0f b6 00             	movzbl (%eax),%eax
     6af:	3c 39                	cmp    $0x39,%al
     6b1:	7e c9                	jle    67c <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
     6b3:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     6b6:	c9                   	leave  
     6b7:	c3                   	ret    

000006b8 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
     6b8:	55                   	push   %ebp
     6b9:	89 e5                	mov    %esp,%ebp
     6bb:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
     6be:	8b 45 08             	mov    0x8(%ebp),%eax
     6c1:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
     6c4:	8b 45 0c             	mov    0xc(%ebp),%eax
     6c7:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
     6ca:	eb 13                	jmp    6df <memmove+0x27>
    *dst++ = *src++;
     6cc:	8b 45 f8             	mov    -0x8(%ebp),%eax
     6cf:	0f b6 10             	movzbl (%eax),%edx
     6d2:	8b 45 fc             	mov    -0x4(%ebp),%eax
     6d5:	88 10                	mov    %dl,(%eax)
     6d7:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     6db:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
     6df:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
     6e3:	0f 9f c0             	setg   %al
     6e6:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
     6ea:	84 c0                	test   %al,%al
     6ec:	75 de                	jne    6cc <memmove+0x14>
    *dst++ = *src++;
  return vdst;
     6ee:	8b 45 08             	mov    0x8(%ebp),%eax
}
     6f1:	c9                   	leave  
     6f2:	c3                   	ret    
     6f3:	90                   	nop

000006f4 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
     6f4:	b8 01 00 00 00       	mov    $0x1,%eax
     6f9:	cd 40                	int    $0x40
     6fb:	c3                   	ret    

000006fc <exit>:
SYSCALL(exit)
     6fc:	b8 02 00 00 00       	mov    $0x2,%eax
     701:	cd 40                	int    $0x40
     703:	c3                   	ret    

00000704 <wait>:
SYSCALL(wait)
     704:	b8 03 00 00 00       	mov    $0x3,%eax
     709:	cd 40                	int    $0x40
     70b:	c3                   	ret    

0000070c <pipe>:
SYSCALL(pipe)
     70c:	b8 04 00 00 00       	mov    $0x4,%eax
     711:	cd 40                	int    $0x40
     713:	c3                   	ret    

00000714 <read>:
SYSCALL(read)
     714:	b8 05 00 00 00       	mov    $0x5,%eax
     719:	cd 40                	int    $0x40
     71b:	c3                   	ret    

0000071c <write>:
SYSCALL(write)
     71c:	b8 10 00 00 00       	mov    $0x10,%eax
     721:	cd 40                	int    $0x40
     723:	c3                   	ret    

00000724 <close>:
SYSCALL(close)
     724:	b8 15 00 00 00       	mov    $0x15,%eax
     729:	cd 40                	int    $0x40
     72b:	c3                   	ret    

0000072c <kill>:
SYSCALL(kill)
     72c:	b8 06 00 00 00       	mov    $0x6,%eax
     731:	cd 40                	int    $0x40
     733:	c3                   	ret    

00000734 <exec>:
SYSCALL(exec)
     734:	b8 07 00 00 00       	mov    $0x7,%eax
     739:	cd 40                	int    $0x40
     73b:	c3                   	ret    

0000073c <open>:
SYSCALL(open)
     73c:	b8 0f 00 00 00       	mov    $0xf,%eax
     741:	cd 40                	int    $0x40
     743:	c3                   	ret    

00000744 <mknod>:
SYSCALL(mknod)
     744:	b8 11 00 00 00       	mov    $0x11,%eax
     749:	cd 40                	int    $0x40
     74b:	c3                   	ret    

0000074c <unlink>:
SYSCALL(unlink)
     74c:	b8 12 00 00 00       	mov    $0x12,%eax
     751:	cd 40                	int    $0x40
     753:	c3                   	ret    

00000754 <fstat>:
SYSCALL(fstat)
     754:	b8 08 00 00 00       	mov    $0x8,%eax
     759:	cd 40                	int    $0x40
     75b:	c3                   	ret    

0000075c <link>:
SYSCALL(link)
     75c:	b8 13 00 00 00       	mov    $0x13,%eax
     761:	cd 40                	int    $0x40
     763:	c3                   	ret    

00000764 <mkdir>:
SYSCALL(mkdir)
     764:	b8 14 00 00 00       	mov    $0x14,%eax
     769:	cd 40                	int    $0x40
     76b:	c3                   	ret    

0000076c <chdir>:
SYSCALL(chdir)
     76c:	b8 09 00 00 00       	mov    $0x9,%eax
     771:	cd 40                	int    $0x40
     773:	c3                   	ret    

00000774 <dup>:
SYSCALL(dup)
     774:	b8 0a 00 00 00       	mov    $0xa,%eax
     779:	cd 40                	int    $0x40
     77b:	c3                   	ret    

0000077c <getpid>:
SYSCALL(getpid)
     77c:	b8 0b 00 00 00       	mov    $0xb,%eax
     781:	cd 40                	int    $0x40
     783:	c3                   	ret    

00000784 <sbrk>:
SYSCALL(sbrk)
     784:	b8 0c 00 00 00       	mov    $0xc,%eax
     789:	cd 40                	int    $0x40
     78b:	c3                   	ret    

0000078c <sleep>:
SYSCALL(sleep)
     78c:	b8 0d 00 00 00       	mov    $0xd,%eax
     791:	cd 40                	int    $0x40
     793:	c3                   	ret    

00000794 <uptime>:
SYSCALL(uptime)
     794:	b8 0e 00 00 00       	mov    $0xe,%eax
     799:	cd 40                	int    $0x40
     79b:	c3                   	ret    

0000079c <signal>:

//our addition
SYSCALL(signal)
     79c:	b8 1f 00 00 00       	mov    $0x1f,%eax
     7a1:	cd 40                	int    $0x40
     7a3:	c3                   	ret    

000007a4 <sigsend>:
SYSCALL(sigsend)
     7a4:	b8 20 00 00 00       	mov    $0x20,%eax
     7a9:	cd 40                	int    $0x40
     7ab:	c3                   	ret    

000007ac <alarm>:
SYSCALL(alarm)
     7ac:	b8 21 00 00 00       	mov    $0x21,%eax
     7b1:	cd 40                	int    $0x40
     7b3:	c3                   	ret    

000007b4 <getTicks>:
SYSCALL(getTicks)
     7b4:	b8 22 00 00 00       	mov    $0x22,%eax
     7b9:	cd 40                	int    $0x40
     7bb:	c3                   	ret    

000007bc <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
     7bc:	55                   	push   %ebp
     7bd:	89 e5                	mov    %esp,%ebp
     7bf:	83 ec 28             	sub    $0x28,%esp
     7c2:	8b 45 0c             	mov    0xc(%ebp),%eax
     7c5:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
     7c8:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     7cf:	00 
     7d0:	8d 45 f4             	lea    -0xc(%ebp),%eax
     7d3:	89 44 24 04          	mov    %eax,0x4(%esp)
     7d7:	8b 45 08             	mov    0x8(%ebp),%eax
     7da:	89 04 24             	mov    %eax,(%esp)
     7dd:	e8 3a ff ff ff       	call   71c <write>
}
     7e2:	c9                   	leave  
     7e3:	c3                   	ret    

000007e4 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
     7e4:	55                   	push   %ebp
     7e5:	89 e5                	mov    %esp,%ebp
     7e7:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
     7ea:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
     7f1:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
     7f5:	74 17                	je     80e <printint+0x2a>
     7f7:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     7fb:	79 11                	jns    80e <printint+0x2a>
    neg = 1;
     7fd:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
     804:	8b 45 0c             	mov    0xc(%ebp),%eax
     807:	f7 d8                	neg    %eax
     809:	89 45 ec             	mov    %eax,-0x14(%ebp)
     80c:	eb 06                	jmp    814 <printint+0x30>
  } else {
    x = xx;
     80e:	8b 45 0c             	mov    0xc(%ebp),%eax
     811:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
     814:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
     81b:	8b 4d 10             	mov    0x10(%ebp),%ecx
     81e:	8b 45 ec             	mov    -0x14(%ebp),%eax
     821:	ba 00 00 00 00       	mov    $0x0,%edx
     826:	f7 f1                	div    %ecx
     828:	89 d0                	mov    %edx,%eax
     82a:	0f b6 80 24 1b 00 00 	movzbl 0x1b24(%eax),%eax
     831:	8d 4d dc             	lea    -0x24(%ebp),%ecx
     834:	8b 55 f4             	mov    -0xc(%ebp),%edx
     837:	01 ca                	add    %ecx,%edx
     839:	88 02                	mov    %al,(%edx)
     83b:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
     83f:	8b 55 10             	mov    0x10(%ebp),%edx
     842:	89 55 d4             	mov    %edx,-0x2c(%ebp)
     845:	8b 45 ec             	mov    -0x14(%ebp),%eax
     848:	ba 00 00 00 00       	mov    $0x0,%edx
     84d:	f7 75 d4             	divl   -0x2c(%ebp)
     850:	89 45 ec             	mov    %eax,-0x14(%ebp)
     853:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     857:	75 c2                	jne    81b <printint+0x37>
  if(neg)
     859:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     85d:	74 2e                	je     88d <printint+0xa9>
    buf[i++] = '-';
     85f:	8d 55 dc             	lea    -0x24(%ebp),%edx
     862:	8b 45 f4             	mov    -0xc(%ebp),%eax
     865:	01 d0                	add    %edx,%eax
     867:	c6 00 2d             	movb   $0x2d,(%eax)
     86a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
     86e:	eb 1d                	jmp    88d <printint+0xa9>
    putc(fd, buf[i]);
     870:	8d 55 dc             	lea    -0x24(%ebp),%edx
     873:	8b 45 f4             	mov    -0xc(%ebp),%eax
     876:	01 d0                	add    %edx,%eax
     878:	0f b6 00             	movzbl (%eax),%eax
     87b:	0f be c0             	movsbl %al,%eax
     87e:	89 44 24 04          	mov    %eax,0x4(%esp)
     882:	8b 45 08             	mov    0x8(%ebp),%eax
     885:	89 04 24             	mov    %eax,(%esp)
     888:	e8 2f ff ff ff       	call   7bc <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
     88d:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
     891:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     895:	79 d9                	jns    870 <printint+0x8c>
    putc(fd, buf[i]);
}
     897:	c9                   	leave  
     898:	c3                   	ret    

00000899 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
     899:	55                   	push   %ebp
     89a:	89 e5                	mov    %esp,%ebp
     89c:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
     89f:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
     8a6:	8d 45 0c             	lea    0xc(%ebp),%eax
     8a9:	83 c0 04             	add    $0x4,%eax
     8ac:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
     8af:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
     8b6:	e9 7d 01 00 00       	jmp    a38 <printf+0x19f>
    c = fmt[i] & 0xff;
     8bb:	8b 55 0c             	mov    0xc(%ebp),%edx
     8be:	8b 45 f0             	mov    -0x10(%ebp),%eax
     8c1:	01 d0                	add    %edx,%eax
     8c3:	0f b6 00             	movzbl (%eax),%eax
     8c6:	0f be c0             	movsbl %al,%eax
     8c9:	25 ff 00 00 00       	and    $0xff,%eax
     8ce:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
     8d1:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     8d5:	75 2c                	jne    903 <printf+0x6a>
      if(c == '%'){
     8d7:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     8db:	75 0c                	jne    8e9 <printf+0x50>
        state = '%';
     8dd:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
     8e4:	e9 4b 01 00 00       	jmp    a34 <printf+0x19b>
      } else {
        putc(fd, c);
     8e9:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8ec:	0f be c0             	movsbl %al,%eax
     8ef:	89 44 24 04          	mov    %eax,0x4(%esp)
     8f3:	8b 45 08             	mov    0x8(%ebp),%eax
     8f6:	89 04 24             	mov    %eax,(%esp)
     8f9:	e8 be fe ff ff       	call   7bc <putc>
     8fe:	e9 31 01 00 00       	jmp    a34 <printf+0x19b>
      }
    } else if(state == '%'){
     903:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
     907:	0f 85 27 01 00 00    	jne    a34 <printf+0x19b>
      if(c == 'd'){
     90d:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
     911:	75 2d                	jne    940 <printf+0xa7>
        printint(fd, *ap, 10, 1);
     913:	8b 45 e8             	mov    -0x18(%ebp),%eax
     916:	8b 00                	mov    (%eax),%eax
     918:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
     91f:	00 
     920:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
     927:	00 
     928:	89 44 24 04          	mov    %eax,0x4(%esp)
     92c:	8b 45 08             	mov    0x8(%ebp),%eax
     92f:	89 04 24             	mov    %eax,(%esp)
     932:	e8 ad fe ff ff       	call   7e4 <printint>
        ap++;
     937:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     93b:	e9 ed 00 00 00       	jmp    a2d <printf+0x194>
      } else if(c == 'x' || c == 'p'){
     940:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
     944:	74 06                	je     94c <printf+0xb3>
     946:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
     94a:	75 2d                	jne    979 <printf+0xe0>
        printint(fd, *ap, 16, 0);
     94c:	8b 45 e8             	mov    -0x18(%ebp),%eax
     94f:	8b 00                	mov    (%eax),%eax
     951:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
     958:	00 
     959:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     960:	00 
     961:	89 44 24 04          	mov    %eax,0x4(%esp)
     965:	8b 45 08             	mov    0x8(%ebp),%eax
     968:	89 04 24             	mov    %eax,(%esp)
     96b:	e8 74 fe ff ff       	call   7e4 <printint>
        ap++;
     970:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     974:	e9 b4 00 00 00       	jmp    a2d <printf+0x194>
      } else if(c == 's'){
     979:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
     97d:	75 46                	jne    9c5 <printf+0x12c>
        s = (char*)*ap;
     97f:	8b 45 e8             	mov    -0x18(%ebp),%eax
     982:	8b 00                	mov    (%eax),%eax
     984:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
     987:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
     98b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     98f:	75 27                	jne    9b8 <printf+0x11f>
          s = "(null)";
     991:	c7 45 f4 f0 12 00 00 	movl   $0x12f0,-0xc(%ebp)
        while(*s != 0){
     998:	eb 1e                	jmp    9b8 <printf+0x11f>
          putc(fd, *s);
     99a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     99d:	0f b6 00             	movzbl (%eax),%eax
     9a0:	0f be c0             	movsbl %al,%eax
     9a3:	89 44 24 04          	mov    %eax,0x4(%esp)
     9a7:	8b 45 08             	mov    0x8(%ebp),%eax
     9aa:	89 04 24             	mov    %eax,(%esp)
     9ad:	e8 0a fe ff ff       	call   7bc <putc>
          s++;
     9b2:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     9b6:	eb 01                	jmp    9b9 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
     9b8:	90                   	nop
     9b9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     9bc:	0f b6 00             	movzbl (%eax),%eax
     9bf:	84 c0                	test   %al,%al
     9c1:	75 d7                	jne    99a <printf+0x101>
     9c3:	eb 68                	jmp    a2d <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
     9c5:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
     9c9:	75 1d                	jne    9e8 <printf+0x14f>
        putc(fd, *ap);
     9cb:	8b 45 e8             	mov    -0x18(%ebp),%eax
     9ce:	8b 00                	mov    (%eax),%eax
     9d0:	0f be c0             	movsbl %al,%eax
     9d3:	89 44 24 04          	mov    %eax,0x4(%esp)
     9d7:	8b 45 08             	mov    0x8(%ebp),%eax
     9da:	89 04 24             	mov    %eax,(%esp)
     9dd:	e8 da fd ff ff       	call   7bc <putc>
        ap++;
     9e2:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     9e6:	eb 45                	jmp    a2d <printf+0x194>
      } else if(c == '%'){
     9e8:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     9ec:	75 17                	jne    a05 <printf+0x16c>
        putc(fd, c);
     9ee:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     9f1:	0f be c0             	movsbl %al,%eax
     9f4:	89 44 24 04          	mov    %eax,0x4(%esp)
     9f8:	8b 45 08             	mov    0x8(%ebp),%eax
     9fb:	89 04 24             	mov    %eax,(%esp)
     9fe:	e8 b9 fd ff ff       	call   7bc <putc>
     a03:	eb 28                	jmp    a2d <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
     a05:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
     a0c:	00 
     a0d:	8b 45 08             	mov    0x8(%ebp),%eax
     a10:	89 04 24             	mov    %eax,(%esp)
     a13:	e8 a4 fd ff ff       	call   7bc <putc>
        putc(fd, c);
     a18:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     a1b:	0f be c0             	movsbl %al,%eax
     a1e:	89 44 24 04          	mov    %eax,0x4(%esp)
     a22:	8b 45 08             	mov    0x8(%ebp),%eax
     a25:	89 04 24             	mov    %eax,(%esp)
     a28:	e8 8f fd ff ff       	call   7bc <putc>
      }
      state = 0;
     a2d:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
     a34:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
     a38:	8b 55 0c             	mov    0xc(%ebp),%edx
     a3b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a3e:	01 d0                	add    %edx,%eax
     a40:	0f b6 00             	movzbl (%eax),%eax
     a43:	84 c0                	test   %al,%al
     a45:	0f 85 70 fe ff ff    	jne    8bb <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
     a4b:	c9                   	leave  
     a4c:	c3                   	ret    
     a4d:	66 90                	xchg   %ax,%ax
     a4f:	90                   	nop

00000a50 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
     a50:	55                   	push   %ebp
     a51:	89 e5                	mov    %esp,%ebp
     a53:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
     a56:	8b 45 08             	mov    0x8(%ebp),%eax
     a59:	83 e8 08             	sub    $0x8,%eax
     a5c:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     a5f:	a1 48 1b 00 00       	mov    0x1b48,%eax
     a64:	89 45 fc             	mov    %eax,-0x4(%ebp)
     a67:	eb 24                	jmp    a8d <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
     a69:	8b 45 fc             	mov    -0x4(%ebp),%eax
     a6c:	8b 00                	mov    (%eax),%eax
     a6e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     a71:	77 12                	ja     a85 <free+0x35>
     a73:	8b 45 f8             	mov    -0x8(%ebp),%eax
     a76:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     a79:	77 24                	ja     a9f <free+0x4f>
     a7b:	8b 45 fc             	mov    -0x4(%ebp),%eax
     a7e:	8b 00                	mov    (%eax),%eax
     a80:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     a83:	77 1a                	ja     a9f <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     a85:	8b 45 fc             	mov    -0x4(%ebp),%eax
     a88:	8b 00                	mov    (%eax),%eax
     a8a:	89 45 fc             	mov    %eax,-0x4(%ebp)
     a8d:	8b 45 f8             	mov    -0x8(%ebp),%eax
     a90:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     a93:	76 d4                	jbe    a69 <free+0x19>
     a95:	8b 45 fc             	mov    -0x4(%ebp),%eax
     a98:	8b 00                	mov    (%eax),%eax
     a9a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     a9d:	76 ca                	jbe    a69 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
     a9f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     aa2:	8b 40 04             	mov    0x4(%eax),%eax
     aa5:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     aac:	8b 45 f8             	mov    -0x8(%ebp),%eax
     aaf:	01 c2                	add    %eax,%edx
     ab1:	8b 45 fc             	mov    -0x4(%ebp),%eax
     ab4:	8b 00                	mov    (%eax),%eax
     ab6:	39 c2                	cmp    %eax,%edx
     ab8:	75 24                	jne    ade <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
     aba:	8b 45 f8             	mov    -0x8(%ebp),%eax
     abd:	8b 50 04             	mov    0x4(%eax),%edx
     ac0:	8b 45 fc             	mov    -0x4(%ebp),%eax
     ac3:	8b 00                	mov    (%eax),%eax
     ac5:	8b 40 04             	mov    0x4(%eax),%eax
     ac8:	01 c2                	add    %eax,%edx
     aca:	8b 45 f8             	mov    -0x8(%ebp),%eax
     acd:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
     ad0:	8b 45 fc             	mov    -0x4(%ebp),%eax
     ad3:	8b 00                	mov    (%eax),%eax
     ad5:	8b 10                	mov    (%eax),%edx
     ad7:	8b 45 f8             	mov    -0x8(%ebp),%eax
     ada:	89 10                	mov    %edx,(%eax)
     adc:	eb 0a                	jmp    ae8 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
     ade:	8b 45 fc             	mov    -0x4(%ebp),%eax
     ae1:	8b 10                	mov    (%eax),%edx
     ae3:	8b 45 f8             	mov    -0x8(%ebp),%eax
     ae6:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
     ae8:	8b 45 fc             	mov    -0x4(%ebp),%eax
     aeb:	8b 40 04             	mov    0x4(%eax),%eax
     aee:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     af5:	8b 45 fc             	mov    -0x4(%ebp),%eax
     af8:	01 d0                	add    %edx,%eax
     afa:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     afd:	75 20                	jne    b1f <free+0xcf>
    p->s.size += bp->s.size;
     aff:	8b 45 fc             	mov    -0x4(%ebp),%eax
     b02:	8b 50 04             	mov    0x4(%eax),%edx
     b05:	8b 45 f8             	mov    -0x8(%ebp),%eax
     b08:	8b 40 04             	mov    0x4(%eax),%eax
     b0b:	01 c2                	add    %eax,%edx
     b0d:	8b 45 fc             	mov    -0x4(%ebp),%eax
     b10:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
     b13:	8b 45 f8             	mov    -0x8(%ebp),%eax
     b16:	8b 10                	mov    (%eax),%edx
     b18:	8b 45 fc             	mov    -0x4(%ebp),%eax
     b1b:	89 10                	mov    %edx,(%eax)
     b1d:	eb 08                	jmp    b27 <free+0xd7>
  } else
    p->s.ptr = bp;
     b1f:	8b 45 fc             	mov    -0x4(%ebp),%eax
     b22:	8b 55 f8             	mov    -0x8(%ebp),%edx
     b25:	89 10                	mov    %edx,(%eax)
  freep = p;
     b27:	8b 45 fc             	mov    -0x4(%ebp),%eax
     b2a:	a3 48 1b 00 00       	mov    %eax,0x1b48
}
     b2f:	c9                   	leave  
     b30:	c3                   	ret    

00000b31 <morecore>:

static Header*
morecore(uint nu)
{
     b31:	55                   	push   %ebp
     b32:	89 e5                	mov    %esp,%ebp
     b34:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
     b37:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
     b3e:	77 07                	ja     b47 <morecore+0x16>
    nu = 4096;
     b40:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
     b47:	8b 45 08             	mov    0x8(%ebp),%eax
     b4a:	c1 e0 03             	shl    $0x3,%eax
     b4d:	89 04 24             	mov    %eax,(%esp)
     b50:	e8 2f fc ff ff       	call   784 <sbrk>
     b55:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
     b58:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
     b5c:	75 07                	jne    b65 <morecore+0x34>
    return 0;
     b5e:	b8 00 00 00 00       	mov    $0x0,%eax
     b63:	eb 22                	jmp    b87 <morecore+0x56>
  hp = (Header*)p;
     b65:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b68:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
     b6b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     b6e:	8b 55 08             	mov    0x8(%ebp),%edx
     b71:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
     b74:	8b 45 f0             	mov    -0x10(%ebp),%eax
     b77:	83 c0 08             	add    $0x8,%eax
     b7a:	89 04 24             	mov    %eax,(%esp)
     b7d:	e8 ce fe ff ff       	call   a50 <free>
  return freep;
     b82:	a1 48 1b 00 00       	mov    0x1b48,%eax
}
     b87:	c9                   	leave  
     b88:	c3                   	ret    

00000b89 <malloc>:

void*
malloc(uint nbytes)
{
     b89:	55                   	push   %ebp
     b8a:	89 e5                	mov    %esp,%ebp
     b8c:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
     b8f:	8b 45 08             	mov    0x8(%ebp),%eax
     b92:	83 c0 07             	add    $0x7,%eax
     b95:	c1 e8 03             	shr    $0x3,%eax
     b98:	83 c0 01             	add    $0x1,%eax
     b9b:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
     b9e:	a1 48 1b 00 00       	mov    0x1b48,%eax
     ba3:	89 45 f0             	mov    %eax,-0x10(%ebp)
     ba6:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     baa:	75 23                	jne    bcf <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
     bac:	c7 45 f0 40 1b 00 00 	movl   $0x1b40,-0x10(%ebp)
     bb3:	8b 45 f0             	mov    -0x10(%ebp),%eax
     bb6:	a3 48 1b 00 00       	mov    %eax,0x1b48
     bbb:	a1 48 1b 00 00       	mov    0x1b48,%eax
     bc0:	a3 40 1b 00 00       	mov    %eax,0x1b40
    base.s.size = 0;
     bc5:	c7 05 44 1b 00 00 00 	movl   $0x0,0x1b44
     bcc:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     bcf:	8b 45 f0             	mov    -0x10(%ebp),%eax
     bd2:	8b 00                	mov    (%eax),%eax
     bd4:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
     bd7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bda:	8b 40 04             	mov    0x4(%eax),%eax
     bdd:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     be0:	72 4d                	jb     c2f <malloc+0xa6>
      if(p->s.size == nunits)
     be2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     be5:	8b 40 04             	mov    0x4(%eax),%eax
     be8:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     beb:	75 0c                	jne    bf9 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
     bed:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bf0:	8b 10                	mov    (%eax),%edx
     bf2:	8b 45 f0             	mov    -0x10(%ebp),%eax
     bf5:	89 10                	mov    %edx,(%eax)
     bf7:	eb 26                	jmp    c1f <malloc+0x96>
      else {
        p->s.size -= nunits;
     bf9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bfc:	8b 40 04             	mov    0x4(%eax),%eax
     bff:	89 c2                	mov    %eax,%edx
     c01:	2b 55 ec             	sub    -0x14(%ebp),%edx
     c04:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c07:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
     c0a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c0d:	8b 40 04             	mov    0x4(%eax),%eax
     c10:	c1 e0 03             	shl    $0x3,%eax
     c13:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
     c16:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c19:	8b 55 ec             	mov    -0x14(%ebp),%edx
     c1c:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
     c1f:	8b 45 f0             	mov    -0x10(%ebp),%eax
     c22:	a3 48 1b 00 00       	mov    %eax,0x1b48
      return (void*)(p + 1);
     c27:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c2a:	83 c0 08             	add    $0x8,%eax
     c2d:	eb 38                	jmp    c67 <malloc+0xde>
    }
    if(p == freep)
     c2f:	a1 48 1b 00 00       	mov    0x1b48,%eax
     c34:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     c37:	75 1b                	jne    c54 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
     c39:	8b 45 ec             	mov    -0x14(%ebp),%eax
     c3c:	89 04 24             	mov    %eax,(%esp)
     c3f:	e8 ed fe ff ff       	call   b31 <morecore>
     c44:	89 45 f4             	mov    %eax,-0xc(%ebp)
     c47:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     c4b:	75 07                	jne    c54 <malloc+0xcb>
        return 0;
     c4d:	b8 00 00 00 00       	mov    $0x0,%eax
     c52:	eb 13                	jmp    c67 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     c54:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c57:	89 45 f0             	mov    %eax,-0x10(%ebp)
     c5a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c5d:	8b 00                	mov    (%eax),%eax
     c5f:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
     c62:	e9 70 ff ff ff       	jmp    bd7 <malloc+0x4e>
}
     c67:	c9                   	leave  
     c68:	c3                   	ret    
     c69:	66 90                	xchg   %ax,%ax
     c6b:	90                   	nop

00000c6c <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
     c6c:	55                   	push   %ebp
     c6d:	89 e5                	mov    %esp,%ebp
     c6f:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
     c72:	c7 05 60 1b 00 00 00 	movl   $0x0,0x1b60
     c79:	00 00 00 
	STORE_ESP(ttable[0].esp);
     c7c:	89 e0                	mov    %esp,%eax
     c7e:	a3 64 1b 00 00       	mov    %eax,0x1b64
	STORE_EBP(ttable[0].ebp);
     c83:	89 e8                	mov    %ebp,%eax
     c85:	a3 68 1b 00 00       	mov    %eax,0x1b68
	ttable[0].state = T_RUNNING;
     c8a:	c7 05 70 1b 00 00 01 	movl   $0x1,0x1b70
     c91:	00 00 00 
	ttable[0].wait_num = 0;
     c94:	c7 05 74 1c 00 00 00 	movl   $0x0,0x1c74
     c9b:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     c9e:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     ca5:	eb 2c                	jmp    cd3 <uthread_init+0x67>
	{
		ttable[i].tid = i;
     ca7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     caa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cb0:	8d 90 60 1b 00 00    	lea    0x1b60(%eax),%edx
     cb6:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cb9:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
     cbb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cbe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cc4:	05 70 1b 00 00       	add    $0x1b70,%eax
     cc9:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     ccf:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     cd3:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     cd7:	7e ce                	jle    ca7 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
     cd9:	c7 44 24 04 5f 0f 00 	movl   $0xf5f,0x4(%esp)
     ce0:	00 
     ce1:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
     ce8:	e8 af fa ff ff       	call   79c <signal>
	alarm(THREAD_QUANTA);
     ced:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     cf4:	e8 b3 fa ff ff       	call   7ac <alarm>
}
     cf9:	c9                   	leave  
     cfa:	c3                   	ret    

00000cfb <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
     cfb:	55                   	push   %ebp
     cfc:	89 e5                	mov    %esp,%ebp
     cfe:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
     d01:	60                   	pusha  
	ticks = getTicks();
     d02:	e8 ad fa ff ff       	call   7b4 <getTicks>
     d07:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
     d0a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     d11:	e8 96 fa ff ff       	call   7ac <alarm>
	asm("popa");
     d16:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
     d17:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     d1e:	e9 02 01 00 00       	jmp    e25 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
     d23:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d26:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d2c:	05 70 1b 00 00       	add    $0x1b70,%eax
     d31:	8b 00                	mov    (%eax),%eax
     d33:	85 c0                	test   %eax,%eax
     d35:	0f 85 e6 00 00 00    	jne    e21 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
     d3b:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
     d42:	e8 42 fe ff ff       	call   b89 <malloc>
     d47:	8b 55 f4             	mov    -0xc(%ebp),%edx
     d4a:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     d50:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
     d56:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
     d59:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d5c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d62:	05 60 1b 00 00       	add    $0x1b60,%eax
     d67:	8b 40 0c             	mov    0xc(%eax),%eax
     d6a:	05 00 10 00 00       	add    $0x1000,%eax
     d6f:	89 c4                	mov    %eax,%esp
			PUSH(arg);
     d71:	8b 45 0c             	mov    0xc(%ebp),%eax
     d74:	89 c7                	mov    %eax,%edi
     d76:	57                   	push   %edi
			PUSH(uthread_exit);
     d77:	b8 e5 0f 00 00       	mov    $0xfe5,%eax
     d7c:	89 c7                	mov    %eax,%edi
     d7e:	57                   	push   %edi
			PUSH(start_func);
     d7f:	8b 45 08             	mov    0x8(%ebp),%eax
     d82:	89 c7                	mov    %eax,%edi
     d84:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
     d85:	b8 00 00 00 00       	mov    $0x0,%eax
     d8a:	89 c7                	mov    %eax,%edi
     d8c:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
     d8d:	89 e0                	mov    %esp,%eax
     d8f:	8b 55 f4             	mov    -0xc(%ebp),%edx
     d92:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     d98:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
     d9e:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
     da1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     da4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     daa:	05 60 1b 00 00       	add    $0x1b60,%eax
     daf:	8b 40 08             	mov    0x8(%eax),%eax
     db2:	8b 55 f4             	mov    -0xc(%ebp),%edx
     db5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dbb:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
     dc1:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
     dc4:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     dc9:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     dcf:	05 60 1b 00 00       	add    $0x1b60,%eax
     dd4:	8b 40 04             	mov    0x4(%eax),%eax
     dd7:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
     dd9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ddc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     de2:	05 70 1b 00 00       	add    $0x1b70,%eax
     de7:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
     ded:	8b 45 f4             	mov    -0xc(%ebp),%eax
     df0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     df6:	05 70 1c 00 00       	add    $0x1c70,%eax
     dfb:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
     e02:	60                   	pusha  
			alarm(ticks);
     e03:	8b 45 f0             	mov    -0x10(%ebp),%eax
     e06:	89 04 24             	mov    %eax,(%esp)
     e09:	e8 9e f9 ff ff       	call   7ac <alarm>
			asm("popa");
     e0e:	61                   	popa   
			return ttable[i].tid;
     e0f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     e12:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e18:	05 60 1b 00 00       	add    $0x1b60,%eax
     e1d:	8b 00                	mov    (%eax),%eax
     e1f:	eb 1e                	jmp    e3f <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
     e21:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     e25:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     e29:	0f 8e f4 fe ff ff    	jle    d23 <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
     e2f:	8b 45 f0             	mov    -0x10(%ebp),%eax
     e32:	89 04 24             	mov    %eax,(%esp)
     e35:	e8 72 f9 ff ff       	call   7ac <alarm>
	//failed - no free thread to use
	return -1;
     e3a:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     e3f:	c9                   	leave  
     e40:	c3                   	ret    

00000e41 <safe_exit>:

// task 2.4


void safe_exit()
{
     e41:	55                   	push   %ebp
     e42:	89 e5                	mov    %esp,%ebp
     e44:	83 ec 28             	sub    $0x28,%esp
     e47:	eb 01                	jmp    e4a <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
     e49:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     e4a:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     e51:	eb 25                	jmp    e78 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
     e53:	8b 45 f4             	mov    -0xc(%ebp),%eax
     e56:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e5c:	05 70 1b 00 00       	add    $0x1b70,%eax
     e61:	8b 00                	mov    (%eax),%eax
     e63:	85 c0                	test   %eax,%eax
     e65:	74 0d                	je     e74 <safe_exit+0x33>
				uthread_join(tid);
     e67:	8b 45 f4             	mov    -0xc(%ebp),%eax
     e6a:	89 04 24             	mov    %eax,(%esp)
     e6d:	e8 1d 02 00 00       	call   108f <uthread_join>
				break;
     e72:	eb 0a                	jmp    e7e <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     e74:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     e78:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     e7c:	7e d5                	jle    e53 <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
     e7e:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
     e82:	75 c5                	jne    e49 <safe_exit+0x8>
			exit();
     e84:	e8 73 f8 ff ff       	call   6fc <exit>

00000e89 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
     e89:	55                   	push   %ebp
     e8a:	89 e5                	mov    %esp,%ebp
     e8c:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
     e8f:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     e94:	8d 50 01             	lea    0x1(%eax),%edx
     e97:	89 d0                	mov    %edx,%eax
     e99:	c1 f8 1f             	sar    $0x1f,%eax
     e9c:	c1 e8 1a             	shr    $0x1a,%eax
     e9f:	01 c2                	add    %eax,%edx
     ea1:	83 e2 3f             	and    $0x3f,%edx
     ea4:	89 d1                	mov    %edx,%ecx
     ea6:	29 c1                	sub    %eax,%ecx
     ea8:	89 c8                	mov    %ecx,%eax
     eaa:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     ead:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     eb4:	eb 20                	jmp    ed6 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
     eb6:	8b 45 f0             	mov    -0x10(%ebp),%eax
     eb9:	8d 50 01             	lea    0x1(%eax),%edx
     ebc:	89 d0                	mov    %edx,%eax
     ebe:	c1 f8 1f             	sar    $0x1f,%eax
     ec1:	c1 e8 1a             	shr    $0x1a,%eax
     ec4:	01 c2                	add    %eax,%edx
     ec6:	83 e2 3f             	and    $0x3f,%edx
     ec9:	89 d1                	mov    %edx,%ecx
     ecb:	29 c1                	sub    %eax,%ecx
     ecd:	89 c8                	mov    %ecx,%eax
     ecf:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     ed2:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     ed6:	8b 45 f0             	mov    -0x10(%ebp),%eax
     ed9:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     edf:	05 70 1b 00 00       	add    $0x1b70,%eax
     ee4:	8b 00                	mov    (%eax),%eax
     ee6:	83 f8 02             	cmp    $0x2,%eax
     ee9:	74 06                	je     ef1 <uthread_switch+0x68>
     eeb:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     eef:	7e c5                	jle    eb6 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
     ef1:	8b 15 4c 1b 00 00    	mov    0x1b4c,%edx
     ef7:	89 e0                	mov    %esp,%eax
     ef9:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     eff:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
     f05:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
     f08:	8b 15 4c 1b 00 00    	mov    0x1b4c,%edx
     f0e:	89 e8                	mov    %ebp,%eax
     f10:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     f16:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
     f1c:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
     f1f:	8b 45 f0             	mov    -0x10(%ebp),%eax
     f22:	a3 4c 1b 00 00       	mov    %eax,0x1b4c
	LOAD_EBP(ttable[c_thread].ebp);
     f27:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     f2c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f32:	05 60 1b 00 00       	add    $0x1b60,%eax
     f37:	8b 40 08             	mov    0x8(%eax),%eax
     f3a:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
     f3c:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     f41:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f47:	05 60 1b 00 00       	add    $0x1b60,%eax
     f4c:	8b 40 04             	mov    0x4(%eax),%eax
     f4f:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
     f51:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     f58:	e8 4f f8 ff ff       	call   7ac <alarm>
}
     f5d:	c9                   	leave  
     f5e:	c3                   	ret    

00000f5f <uthread_yield>:

void uthread_yield()
{
     f5f:	55                   	push   %ebp
     f60:	89 e5                	mov    %esp,%ebp
     f62:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
     f65:	60                   	pusha  
	alarm(0);
     f66:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f6d:	e8 3a f8 ff ff       	call   7ac <alarm>
	ttable[c_thread].state = T_RUNNABLE;
     f72:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     f77:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f7d:	05 70 1b 00 00       	add    $0x1b70,%eax
     f82:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
     f88:	e8 fc fe ff ff       	call   e89 <uthread_switch>
	asm("popa");
     f8d:	61                   	popa   
}
     f8e:	c9                   	leave  
     f8f:	c3                   	ret    

00000f90 <uthread_awake>:

// task 2.5

void uthread_awake()
{
     f90:	55                   	push   %ebp
     f91:	89 e5                	mov    %esp,%ebp
     f93:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     f96:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     f9d:	eb 2c                	jmp    fcb <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
     f9f:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     fa4:	6b d0 46             	imul   $0x46,%eax,%edx
     fa7:	8b 45 fc             	mov    -0x4(%ebp),%eax
     faa:	01 d0                	add    %edx,%eax
     fac:	83 c0 04             	add    $0x4,%eax
     faf:	8b 04 85 64 1b 00 00 	mov    0x1b64(,%eax,4),%eax
     fb6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     fbc:	05 70 1b 00 00       	add    $0x1b70,%eax
     fc1:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     fc7:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     fcb:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     fd0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     fd6:	05 70 1c 00 00       	add    $0x1c70,%eax
     fdb:	8b 40 04             	mov    0x4(%eax),%eax
     fde:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     fe1:	7f bc                	jg     f9f <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
     fe3:	c9                   	leave  
     fe4:	c3                   	ret    

00000fe5 <uthread_exit>:

void uthread_exit()
{
     fe5:	55                   	push   %ebp
     fe6:	89 e5                	mov    %esp,%ebp
     fe8:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     feb:	60                   	pusha  
	alarm(0);
     fec:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     ff3:	e8 b4 f7 ff ff       	call   7ac <alarm>
	asm("popa");
     ff8:	61                   	popa   
	ttable[c_thread].state = T_FREE;
     ff9:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
     ffe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    1004:	05 70 1b 00 00       	add    $0x1b70,%eax
    1009:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
    100f:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
    1014:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    101a:	05 60 1b 00 00       	add    $0x1b60,%eax
    101f:	8b 00                	mov    (%eax),%eax
    1021:	85 c0                	test   %eax,%eax
    1023:	74 1d                	je     1042 <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
    1025:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
    102a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    1030:	05 60 1b 00 00       	add    $0x1b60,%eax
    1035:	8b 40 0c             	mov    0xc(%eax),%eax
    1038:	89 04 24             	mov    %eax,(%esp)
    103b:	e8 10 fa ff ff       	call   a50 <free>
    1040:	eb 05                	jmp    1047 <uthread_exit+0x62>
	else
		safe_exit();
    1042:	e8 fa fd ff ff       	call   e41 <safe_exit>
	uthread_awake();
    1047:	e8 44 ff ff ff       	call   f90 <uthread_awake>
	uthread_switch();
    104c:	e8 38 fe ff ff       	call   e89 <uthread_switch>
	asm("popa");
    1051:	61                   	popa   
}
    1052:	c9                   	leave  
    1053:	c3                   	ret    

00001054 <uthread_self>:

// task 2.6

int uthread_self()
{
    1054:	55                   	push   %ebp
    1055:	89 e5                	mov    %esp,%ebp
	return c_thread;
    1057:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
}
    105c:	5d                   	pop    %ebp
    105d:	c3                   	ret    

0000105e <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
    105e:	55                   	push   %ebp
    105f:	89 e5                	mov    %esp,%ebp
    1061:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
    1064:	60                   	pusha  
	alarm(0);
    1065:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    106c:	e8 3b f7 ff ff       	call   7ac <alarm>
	ttable[c_thread].state = T_SLEEPING;
    1071:	a1 4c 1b 00 00       	mov    0x1b4c,%eax
    1076:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    107c:	05 70 1b 00 00       	add    $0x1b70,%eax
    1081:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
    1087:	e8 fd fd ff ff       	call   e89 <uthread_switch>
	asm("popa");
    108c:	61                   	popa   
}
    108d:	c9                   	leave  
    108e:	c3                   	ret    

0000108f <uthread_join>:

int uthread_join(int tid)
{
    108f:	55                   	push   %ebp
    1090:	89 e5                	mov    %esp,%ebp
    1092:	53                   	push   %ebx
    1093:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
    1096:	60                   	pusha  
	ticks = getTicks();
    1097:	e8 18 f7 ff ff       	call   7b4 <getTicks>
    109c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    109f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    10a6:	e8 01 f7 ff ff       	call   7ac <alarm>
	asm("popa");
    10ab:	61                   	popa   
	if (ttable[tid].state != T_FREE)
    10ac:	8b 45 08             	mov    0x8(%ebp),%eax
    10af:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    10b5:	05 70 1b 00 00       	add    $0x1b70,%eax
    10ba:	8b 00                	mov    (%eax),%eax
    10bc:	85 c0                	test   %eax,%eax
    10be:	74 5e                	je     111e <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
    10c0:	8b 45 08             	mov    0x8(%ebp),%eax
    10c3:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    10c9:	05 10 01 00 00       	add    $0x110,%eax
    10ce:	05 60 1b 00 00       	add    $0x1b60,%eax
    10d3:	8d 48 04             	lea    0x4(%eax),%ecx
    10d6:	8b 45 08             	mov    0x8(%ebp),%eax
    10d9:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
    10df:	05 70 1c 00 00       	add    $0x1c70,%eax
    10e4:	8b 40 04             	mov    0x4(%eax),%eax
    10e7:	8b 15 4c 1b 00 00    	mov    0x1b4c,%edx
    10ed:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
    10f3:	81 c2 60 1b 00 00    	add    $0x1b60,%edx
    10f9:	8b 12                	mov    (%edx),%edx
    10fb:	8b 5d 08             	mov    0x8(%ebp),%ebx
    10fe:	6b db 46             	imul   $0x46,%ebx,%ebx
    1101:	01 c3                	add    %eax,%ebx
    1103:	83 c3 04             	add    $0x4,%ebx
    1106:	89 14 9d 64 1b 00 00 	mov    %edx,0x1b64(,%ebx,4)
    110d:	83 c0 01             	add    $0x1,%eax
    1110:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
    1112:	e8 47 ff ff ff       	call   105e <uthread_sleep>
		return 0;
    1117:	b8 00 00 00 00       	mov    $0x0,%eax
    111c:	eb 12                	jmp    1130 <uthread_join+0xa1>
	}
	asm("pusha");
    111e:	60                   	pusha  
	alarm(ticks);
    111f:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1122:	89 04 24             	mov    %eax,(%esp)
    1125:	e8 82 f6 ff ff       	call   7ac <alarm>
	asm("popa");
    112a:	61                   	popa   
	return -1;
    112b:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
    1130:	83 c4 24             	add    $0x24,%esp
    1133:	5b                   	pop    %ebx
    1134:	5d                   	pop    %ebp
    1135:	c3                   	ret    

00001136 <queue_init>:

void queue_init(struct tqueue *q)
{
    1136:	55                   	push   %ebp
    1137:	89 e5                	mov    %esp,%ebp
	q->head = 0;
    1139:	8b 45 08             	mov    0x8(%ebp),%eax
    113c:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
    1143:	00 00 00 
	q->tail = 0;
    1146:	8b 45 08             	mov    0x8(%ebp),%eax
    1149:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
    1150:	00 00 00 
}
    1153:	5d                   	pop    %ebp
    1154:	c3                   	ret    

00001155 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
    1155:	55                   	push   %ebp
    1156:	89 e5                	mov    %esp,%ebp
    1158:	57                   	push   %edi
    1159:	56                   	push   %esi
    115a:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
    115b:	8b 45 08             	mov    0x8(%ebp),%eax
    115e:	8b 00                	mov    (%eax),%eax
    1160:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
    1166:	8b 45 08             	mov    0x8(%ebp),%eax
    1169:	8b 00                	mov    (%eax),%eax
    116b:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
    1171:	39 c2                	cmp    %eax,%edx
    1173:	75 07                	jne    117c <dequeue+0x27>
		return 0;
    1175:	b9 00 00 00 00       	mov    $0x0,%ecx
    117a:	eb 31                	jmp    11ad <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
    117c:	8b 45 08             	mov    0x8(%ebp),%eax
    117f:	8b 18                	mov    (%eax),%ebx
    1181:	8b 45 08             	mov    0x8(%ebp),%eax
    1184:	8b 10                	mov    (%eax),%edx
    1186:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
    118c:	89 c1                	mov    %eax,%ecx
    118e:	c1 f9 1f             	sar    $0x1f,%ecx
    1191:	c1 e9 1a             	shr    $0x1a,%ecx
    1194:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    1197:	83 e6 3f             	and    $0x3f,%esi
    119a:	89 f7                	mov    %esi,%edi
    119c:	29 cf                	sub    %ecx,%edi
    119e:	89 f9                	mov    %edi,%ecx
    11a0:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
    11a3:	83 c0 01             	add    $0x1,%eax
    11a6:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
    11ac:	90                   	nop
    11ad:	89 c8                	mov    %ecx,%eax
}
    11af:	5b                   	pop    %ebx
    11b0:	5e                   	pop    %esi
    11b1:	5f                   	pop    %edi
    11b2:	5d                   	pop    %ebp
    11b3:	c3                   	ret    

000011b4 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
    11b4:	55                   	push   %ebp
    11b5:	89 e5                	mov    %esp,%ebp
    11b7:	57                   	push   %edi
    11b8:	56                   	push   %esi
    11b9:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
    11ba:	8b 45 08             	mov    0x8(%ebp),%eax
    11bd:	8b 18                	mov    (%eax),%ebx
    11bf:	8b 45 08             	mov    0x8(%ebp),%eax
    11c2:	8b 10                	mov    (%eax),%edx
    11c4:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
    11ca:	89 c1                	mov    %eax,%ecx
    11cc:	c1 f9 1f             	sar    $0x1f,%ecx
    11cf:	c1 e9 1a             	shr    $0x1a,%ecx
    11d2:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    11d5:	83 e6 3f             	and    $0x3f,%esi
    11d8:	89 f7                	mov    %esi,%edi
    11da:	29 cf                	sub    %ecx,%edi
    11dc:	89 f9                	mov    %edi,%ecx
    11de:	8b 35 4c 1b 00 00    	mov    0x1b4c,%esi
    11e4:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
    11ea:	81 c6 60 1b 00 00    	add    $0x1b60,%esi
    11f0:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
    11f3:	83 c0 01             	add    $0x1,%eax
    11f6:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
    11fc:	5b                   	pop    %ebx
    11fd:	5e                   	pop    %esi
    11fe:	5f                   	pop    %edi
    11ff:	5d                   	pop    %ebp
    1200:	c3                   	ret    

00001201 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
    1201:	55                   	push   %ebp
    1202:	89 e5                	mov    %esp,%ebp
    1204:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
    1207:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
    120e:	e8 76 f9 ff ff       	call   b89 <malloc>
    1213:	8b 55 08             	mov    0x8(%ebp),%edx
    1216:	89 02                	mov    %eax,(%edx)
	if (!value)
    1218:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
    121c:	75 0c                	jne    122a <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
    121e:	8b 45 08             	mov    0x8(%ebp),%eax
    1221:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
    1228:	eb 0a                	jmp    1234 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
    122a:	8b 45 08             	mov    0x8(%ebp),%eax
    122d:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
    1234:	c9                   	leave  
    1235:	c3                   	ret    

00001236 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
    1236:	55                   	push   %ebp
    1237:	89 e5                	mov    %esp,%ebp
    1239:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
    123c:	60                   	pusha  
	ticks = getTicks();
    123d:	e8 72 f5 ff ff       	call   7b4 <getTicks>
    1242:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    1245:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    124c:	e8 5b f5 ff ff       	call   7ac <alarm>
	asm("popa");
    1251:	61                   	popa   
	if (semaphore->state == S_LOCKED)
    1252:	8b 45 08             	mov    0x8(%ebp),%eax
    1255:	8b 40 04             	mov    0x4(%eax),%eax
    1258:	83 f8 01             	cmp    $0x1,%eax
    125b:	75 1c                	jne    1279 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
    125d:	8b 45 08             	mov    0x8(%ebp),%eax
    1260:	89 04 24             	mov    %eax,(%esp)
    1263:	e8 4c ff ff ff       	call   11b4 <enqueue>
		uthread_sleep();
    1268:	e8 f1 fd ff ff       	call   105e <uthread_sleep>
		alarm(0);
    126d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1274:	e8 33 f5 ff ff       	call   7ac <alarm>
	}
	semaphore->state = S_LOCKED;
    1279:	8b 45 08             	mov    0x8(%ebp),%eax
    127c:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
    1283:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1286:	89 04 24             	mov    %eax,(%esp)
    1289:	e8 1e f5 ff ff       	call   7ac <alarm>

}
    128e:	c9                   	leave  
    128f:	c3                   	ret    

00001290 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
    1290:	55                   	push   %ebp
    1291:	89 e5                	mov    %esp,%ebp
    1293:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
    1296:	60                   	pusha  
	ticks = getTicks();
    1297:	e8 18 f5 ff ff       	call   7b4 <getTicks>
    129c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    129f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    12a6:	e8 01 f5 ff ff       	call   7ac <alarm>
	asm("popa");
    12ab:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
    12ac:	8b 45 08             	mov    0x8(%ebp),%eax
    12af:	89 04 24             	mov    %eax,(%esp)
    12b2:	e8 9e fe ff ff       	call   1155 <dequeue>
    12b7:	89 45 f0             	mov    %eax,-0x10(%ebp)
    12ba:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
    12be:	75 19                	jne    12d9 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
    12c0:	8b 45 08             	mov    0x8(%ebp),%eax
    12c3:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
    12ca:	60                   	pusha  
		alarm(ticks);
    12cb:	8b 45 f4             	mov    -0xc(%ebp),%eax
    12ce:	89 04 24             	mov    %eax,(%esp)
    12d1:	e8 d6 f4 ff ff       	call   7ac <alarm>
		asm("popa");
    12d6:	61                   	popa   
    12d7:	eb 0f                	jmp    12e8 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
    12d9:	8b 45 f0             	mov    -0x10(%ebp),%eax
    12dc:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
    12e3:	e8 77 fc ff ff       	call   f5f <uthread_yield>
	}
}
    12e8:	c9                   	leave  
    12e9:	c3                   	ret    
